package com.diyunapp.xilinapp.fragments;


import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.adapters.RecycleViewGridAdapter;
import com.diyunapp.xilinapp.bean.YouLikeGoodsBean;
import com.diyunapp.xilinapp.details.GoodsDetailActivity;
import com.diyunapp.xilinapp.details.SearchResultActivity;
import com.diyunapp.xilinapp.details.SearchSetActivity;
import com.diyunapp.xilinapp.main.MainActivity;
import com.diyunapp.xilinapp.myapi.OnRecyclerViewItemClickListener;
import com.diyunapp.xilinapp.utils.FormatConfirm;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nuttysoft.nutand.utils.AppUtil;
import com.nuttysoft.nutand.utils.ViewUtil;
import com.squareup.picasso.Picasso;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.simple.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * A simple {@link Fragment} subclass.
 */
public class IndexFragment extends Fragment implements View.OnClickListener {

    @Bind(R.id.home_convenientBanner)
    ConvenientBanner homeConvenientBanner;
    @Bind(R.id.jujinghuisheng_title_tv)
    TextView jujinghuishengTitleTv;
    @Bind(R.id.jujinghuisheng_info_tv)
    TextView jujinghuishengInfoTv;
    @Bind(R.id.jujinghuisheng_img)
    ImageView jujinghuishengImg;
    @Bind(R.id.xianshiqianggou_title_tv)
    TextView xianshiqianggouTitleTv;
    @Bind(R.id.xianshiqianggou_img)
    ImageView xianshiqianggouImg;
    @Bind(R.id.zhuticuxiao_title_tv)
    TextView zhuticuxiaoTitleTv;
    @Bind(R.id.zhuticuxiao_img)
    ImageView zhuticuxiaoImg;
    @Bind(R.id.dayly_newmore_tv)
    TextView daylyNewmoreTv;
    @Bind(R.id.daynew_left_title_tv)
    TextView daynewLeftTitleTv;
    @Bind(R.id.daynew_left_price_tv)
    TextView daynewLeftPriceTv;
    @Bind(R.id.daynew_left_img)
    ImageView daynewLeftImg;
    @Bind(R.id.daynew_rightup_img)
    ImageView daynewRightupImg;
    @Bind(R.id.daynew_rightup_title_tv)
    TextView daynewRightupTitleTv;
    @Bind(R.id.daynew_rightup_price_tv)
    TextView daynewRightupPriceTv;
    @Bind(R.id.daynew_righdown_img)
    ImageView daynewRighdownImg;
    @Bind(R.id.daynew_rightdown_title_tv)
    TextView daynewRightdownTitleTv;
    @Bind(R.id.daynew_rightdown_price_tv)
    TextView daynewRightdownPriceTv;
    @Bind(R.id.hot_more_tv)
    TextView hotMoreTv;
    @Bind(R.id.hot_left_title_tv)
    TextView hotLeftTitleTv;
    @Bind(R.id.hot_left_price_tv)
    TextView hotLeftPriceTv;
    @Bind(R.id.hot_left_img)
    ImageView hotLeftImg;
    @Bind(R.id.hot_rightup_img)
    ImageView hotRightupImg;
    @Bind(R.id.hot_rightup_title_tv)
    TextView hotRightupTitleTv;
    @Bind(R.id.hot_rightup_price_tv)
    TextView hotRightupPriceTv;
    @Bind(R.id.hot_rightdown_img)
    ImageView hotRightdownImg;
    @Bind(R.id.hot_rightdown_title_tv)
    TextView hotRightdownTitleTv;
    @Bind(R.id.hot_rightdown_price_tv)
    TextView hotRightdownPriceTv;
    @Bind(R.id.bottom_goods_title_tv)
    TextView bottomGoodsTitleTv;
    @Bind(R.id.youlike_more_tv)
    TextView youlikeMoreTv;
    @Bind(R.id.part2_title_tv)
    TextView part2TitleTv;
    @Bind(R.id.part3_title_tv)
    TextView part3TitleTv;
    @Bind(R.id.jujinghuisheng_ll)
    LinearLayout jujinghuishengLl;
    @Bind(R.id.xianshiqianggou_ll)
    LinearLayout xianshiqianggouLl;
    @Bind(R.id.zhuticuxiao_ll)
    LinearLayout zhuticuxiaoLl;
    @Bind(R.id.daynew_left_ll)
    LinearLayout daynewLeftLl;
    @Bind(R.id.daynew_rightup_fl)
    FrameLayout daynewRightupFl;
    @Bind(R.id.daynew_righdown_fl)
    FrameLayout daynewRighdownFl;
    @Bind(R.id.hot_left_ll)
    LinearLayout hotLeftLl;
    @Bind(R.id.hot_rightup_fl)
    FrameLayout hotRightupFl;
    @Bind(R.id.hot_rightdown_fl)
    FrameLayout hotRightdownFl;

    private View topView;
    private List<String> picUrlList = new ArrayList<>();
    private int[] bannerPoint;

    private GridLayoutManager gridLayoutManager;
    private List<YouLikeGoodsBean> goodsLists;
    private RecycleViewGridAdapter recycleViewAdapter;
    private RecyclerView productsRecycleView;
    private SwipeRefreshLayout homeSRL;
    private LinearLayout search_ll;
    private String[] dayNewIdStr = new String[3];
    private String[] HotComIdStr = new String[3];

    private boolean oldState = false;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        EventBus.getDefault().register(this);
        View indexView = inflater.inflate(R.layout.fragment_index, null);

        //手动初始化RecyclerView控件
        search_ll = (LinearLayout)indexView.findViewById(R.id.index_search_ll);
        search_ll.setOnClickListener(this);
        productsRecycleView = (RecyclerView) indexView.findViewById(R.id.products_recycle_view);
        homeSRL = (SwipeRefreshLayout) indexView.findViewById(R.id.home_products_srl);
        //RecyclerView 的head_top
        topView = inflater.inflate(R.layout.home_item_top, null);
        ButterKnife.bind(this, topView);

        initViews();
        getIndex();
        getYouLike();
        return indexView;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        //如果在用户页面，用户的登录状态发生了变化，则再次进入主页时，更新猜您喜欢的内容
        if(hidden)
        {
            oldState = MainActivity.myLogin.isLoginState();
        }
        else
        {
            if(oldState != MainActivity.myLogin.isLoginState())
            {
                oldState = MainActivity.myLogin.isLoginState();
                getYouLike();
            }
        }
        super.onHiddenChanged(hidden);
    }

    private void initViews() {
        daylyNewmoreTv.setOnClickListener(this);
        hotMoreTv.setOnClickListener(this);
        youlikeMoreTv.setOnClickListener(this);
        jujinghuishengLl.setOnClickListener(this);
        xianshiqianggouLl.setOnClickListener(this);
        zhuticuxiaoLl.setOnClickListener(this);
        daynewLeftLl.setOnClickListener(this);
        daynewRightupFl.setOnClickListener(this);
        daynewRighdownFl.setOnClickListener(this);
        hotLeftLl.setOnClickListener(this);
        hotRightupFl.setOnClickListener(this);
        hotRightdownFl.setOnClickListener(this);
        initYourLikeView();
    }


    private void initBanner() {

        //自定义你的Holder，实现更多复杂的界面，不一定是图片翻页，其他任何控件翻页亦可。
        homeConvenientBanner.setPages(
                new CBViewHolderCreator<LocalImageHolderView>() {
                    @Override
                    public LocalImageHolderView createHolder() {
                        return new LocalImageHolderView();
                    }
                }, picUrlList).startTurning(5000);
                //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                if(bannerPoint.length>=2)
                {
                    homeConvenientBanner.setPageIndicator(bannerPoint);
                }

        //设置指示器的方向
        //.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT);
        //设置翻页的效果，不需要翻页效果可用不设
        //.setPageTransformer(Transformer.DefaultTransformer);    集成特效之后会有白屏现象，新版已经分离，如果要集成特效的例子可以看Demo的点击响应。
        //convenientBanner.setManualPageable(false);//设置不能手动影响
    }

    private void initYourLikeView() {
        gridLayoutManager = new GridLayoutManager(getActivity(), 2);
        goodsLists = new ArrayList<>();
        recycleViewAdapter = new RecycleViewGridAdapter(goodsLists);

        //以下是为RecycleView添加头尾的操作，暂不需要，屏蔽掉。
        recycleViewAdapter.addHeadView(topView);
        //recycleViewAdapter.addFootView(endView);

        //如果添加了头部或者尾部 就需要做相关的SpanSize的修改
        recycleViewAdapter.setChangeGridLayoutManager(new RecycleViewGridAdapter.ChangeGridLayoutManagerSpance() {
            @Override
            public void change(final int size, final boolean isAddHead, final boolean isAddFoot) {
                gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                    @Override
                    public int getSpanSize(int position) {
                        int spanSzie = 1;
                        if (isAddHead) {
                            if (position == 0) {
                                spanSzie = gridLayoutManager.getSpanCount();
                            }
                        }

                        if (isAddFoot) {
                            if (position == size) {
                                spanSzie = gridLayoutManager.getSpanCount();
                            }
                        }
                        return spanSzie;
                    }
                });
            }
        });

        productsRecycleView.setLayoutManager(gridLayoutManager);
        productsRecycleView.setAdapter(recycleViewAdapter);
        homeSRL.setColorSchemeColors(R.color.domain_orange, R.color.green,
                R.color.blue, R.color.yellow);

        homeSRL.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Log.d("zhangxiaoxidebug","invoke onRefresh...");
                picUrlList.clear();
                bannerPoint = null;
                goodsLists.clear();
                getIndex();
                getYouLike();
            }
        });

        recycleViewAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int data) {
                //TODO
                Intent likeInt = new Intent(getActivity(), GoodsDetailActivity.class);
                likeInt.putExtra("GoodId",goodsLists.get(data).getGoodId());
                startActivity(likeInt);
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.index_search_ll:
                Intent searchInt = new Intent(getActivity(),SearchSetActivity.class);
                startActivity(searchInt);
                break;
            case R.id.dayly_newmore_tv:
                startIntent("今日上新");
                break;
            case R.id.hot_more_tv:
                startIntent("热门推荐");
                break;
            case R.id.youlike_more_tv:
                startIntent("猜您喜欢");
                break;
            case R.id.jujinghuisheng_ll:
                startIntent("聚精会省");
                break;
            case R.id.xianshiqianggou_ll:
                startIntent("限时抢购");
                break;
            case R.id.zhuticuxiao_ll:
               startIntent("主题促销");
                break;
            case R.id.daynew_left_ll:
                Intent daynewInt1 = new Intent(getActivity(), GoodsDetailActivity.class);
                daynewInt1.putExtra("GoodId",dayNewIdStr[0]);
                startActivity(daynewInt1);
                break;
            case R.id.daynew_rightup_fl:
                Intent daynewInt2 = new Intent(getActivity(), GoodsDetailActivity.class);
                daynewInt2.putExtra("GoodId",dayNewIdStr[1]);
                startActivity(daynewInt2);
                break;
            case R.id.daynew_righdown_fl:
                Intent daynewInt3 = new Intent(getActivity(), GoodsDetailActivity.class);
                daynewInt3.putExtra("GoodId",dayNewIdStr[2]);
                startActivity(daynewInt3);
                break;
            case R.id.hot_left_ll:
                Intent hotInt1 = new Intent(getActivity(), GoodsDetailActivity.class);
                hotInt1.putExtra("GoodId",HotComIdStr[0]);
                startActivity(hotInt1);
                break;
            case R.id.hot_rightup_fl:
                Intent hotInt2 = new Intent(getActivity(), GoodsDetailActivity.class);
                hotInt2.putExtra("GoodId",HotComIdStr[1]);
                startActivity(hotInt2);
                break;
            case R.id.hot_rightdown_fl:
                Intent hotInt3 = new Intent(getActivity(), GoodsDetailActivity.class);
                hotInt3.putExtra("GoodId",HotComIdStr[2]);
                startActivity(hotInt3);
                break;
            default:
                break;
        }

    }

    public class LocalImageHolderView implements Holder<String> {
        private ImageView imageView;

        @Override
        public View createView(Context context) {
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, String data) {
            int screenWidth = AppUtil.getDisplayMetrics(context).heightPixels;
            int targetPicHeight = (int) ViewUtil.dip2px(context, 180);
            Picasso.with(context)
                    .load(data)//int) width * 400 / 1392
//                    .resize((int) targetPicHeight * 1392 / 400, targetPicHeight)
//                    .centerCrop()
                    .config(Bitmap.Config.RGB_565)
                    .error(R.drawable.store_ban_default)
                    .placeholder(R.drawable.store_ban_default)
                    .into(imageView);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    private void getIndex() {
        String url = "http://www.xilingou.com/mobile/index.php?act=index";
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(2000);
        http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        int result = parseProject(responseInfo.result);
                        switch (result) {
                            case 1:
                                break;
                            case 0:
                                Toast.makeText(getActivity(), "读取数据失败！", Toast.LENGTH_LONG).show();
                                break;
                            default:
                                break;
                        }
                    }


                    @Override
                    public void onStart() {

                    }

                    private int parseProject(String result) {
                        Log.i("zhangxiaoxidebug", "home_result=" + result);
                        try {
                            JSONObject jsObjectCode = new JSONObject(result);
                            int code = jsObjectCode.getInt("code");
                            if (code != 200) {
                                return 0;
                            }

                            JSONArray jsArrayDatas = jsObjectCode.getJSONArray("datas");

                            //adv_list解析 内容为banner图片
                            {
                                JSONObject jsObjectAdvlist = jsArrayDatas.getJSONObject(0);
                                JSONObject jsObjectItem = jsObjectAdvlist.getJSONObject("adv_list");
                                JSONArray jsArrayItem = jsObjectItem.getJSONArray("item");
                                bannerPoint = new int[jsArrayItem.length()];
                                for (int img = 0; img < jsArrayItem.length(); img++) {
                                    if (img == 0) {
                                        bannerPoint[img] = R.drawable.picture_off;
                                    } else {
                                        bannerPoint[img] = R.drawable.picture_on;
                                    }

                                    JSONObject jsObjectImage = jsArrayItem.getJSONObject(img);
                                    picUrlList.add(jsObjectImage.getString("image"));
                                }
                                initBanner();
                            }

                            //第一个home2解析， 内容为聚精会省部分
                            {
                                JSONObject jsObjectPart1 = jsArrayDatas.getJSONObject(1);
                                JSONObject jsObjectHome1 = jsObjectPart1.getJSONObject("home2");
                                String home1titleLeft = jsObjectHome1.getString("square_data");
                                String home1detailLeft = jsObjectHome1.getString("square_type");
                                String home1imgLeft = jsObjectHome1.getString("square_image");
                                String home1titlerightup = jsObjectHome1.getString("rectangle1_data");
                                String home1imgrightup = jsObjectHome1.getString("rectangle1_image");
                                String home1titlerightdown = jsObjectHome1.getString("rectangle2_data");
                                String home1imgrightdown = jsObjectHome1.getString("rectangle2_image");

                                jujinghuishengTitleTv.setText(home1titleLeft);
                                jujinghuishengInfoTv.setText(home1detailLeft);
                                ImageLoader.getInstance().displayImage(home1imgLeft, jujinghuishengImg, FormatConfirm.getOption());
                                xianshiqianggouTitleTv.setText(home1titlerightup);
                                ImageLoader.getInstance().displayImage(home1imgrightup, xianshiqianggouImg, FormatConfirm.getOption());
                                zhuticuxiaoTitleTv.setText(home1titlerightdown);
                                ImageLoader.getInstance().displayImage(home1imgrightdown, zhuticuxiaoImg, FormatConfirm.getOption());
                            }

                            //第二个home2解析， 内容为今日上新部分
                            {
                                JSONObject jsObjectPart2 = jsArrayDatas.getJSONObject(2);
                                JSONObject jsObjectHome2 = jsObjectPart2.getJSONObject("goods");
                                String home2title = jsObjectHome2.getString("title");
                                part2TitleTv.setText(home2title);
                                JSONArray jsArrayGoodsList2 = jsObjectHome2.getJSONArray("item");
                                JSONObject jsObjectGood1 = jsArrayGoodsList2.getJSONObject(0);
                                dayNewIdStr[0] = jsObjectGood1.getString("goods_id");
                                String home2nameLeft = jsObjectGood1.getString("goods_name");
                                String home2priceLeft = jsObjectGood1.getString("goods_promotion_price");
                                String home2imgLeft = jsObjectGood1.getString("goods_image");
                                daynewLeftTitleTv.setText(home2nameLeft);
                                daynewLeftPriceTv.setText(home2priceLeft);
                                ImageLoader.getInstance().displayImage(home2imgLeft, daynewLeftImg, FormatConfirm.getOption());
                                JSONObject jsObjectGood2 = jsArrayGoodsList2.getJSONObject(1);
                                dayNewIdStr[1] = jsObjectGood2.getString("goods_id");
                                String home2nameRightup = jsObjectGood2.getString("goods_name");
                                String home2priceRightup = jsObjectGood2.getString("goods_promotion_price");
                                String home2imgRightup = jsObjectGood2.getString("goods_image");
                                daynewRightupTitleTv.setText(home2nameRightup);
                                daynewRightupPriceTv.setText(home2priceRightup);
                                ImageLoader.getInstance().displayImage(home2imgRightup, daynewRightupImg, FormatConfirm.getOption());
                                JSONObject jsObjectGood3 = jsArrayGoodsList2.getJSONObject(2);
                                dayNewIdStr[2] = jsObjectGood3.getString("goods_id");
                                String home2nameRightdown = jsObjectGood3.getString("goods_name");
                                String home2priceRightdown = jsObjectGood3.getString("goods_promotion_price");
                                String home2imgRightdown = jsObjectGood3.getString("goods_image");
                                daynewRightdownTitleTv.setText(home2nameRightdown);
                                daynewRightdownPriceTv.setText(home2priceRightdown);
                                ImageLoader.getInstance().displayImage(home2imgRightdown, daynewRighdownImg, FormatConfirm.getOption());
                            }

                            //第三个home2解析， 内容对应热门推荐部分
                            {
                                JSONObject jsObjectPart3 = jsArrayDatas.getJSONObject(3);
                                JSONObject jsObjectHome3 = jsObjectPart3.getJSONObject("goods");
                                String home3title = jsObjectHome3.getString("title");
                                part3TitleTv.setText(home3title);
                                JSONArray jsArrayGoodsList3 = jsObjectHome3.getJSONArray("item");
                                JSONObject jsObjectGood31 = jsArrayGoodsList3.getJSONObject(0);
                                HotComIdStr[0] = jsObjectGood31.getString("goods_id");
                                String home3nameLeft = jsObjectGood31.getString("goods_name");
                                String home3priceLeft = jsObjectGood31.getString("goods_promotion_price");
                                String home3imgLeft = jsObjectGood31.getString("goods_image");
                                hotLeftTitleTv.setText(home3nameLeft);
                                hotLeftPriceTv.setText(home3priceLeft);
                                ImageLoader.getInstance().displayImage(home3imgLeft, hotLeftImg, FormatConfirm.getOption());
                                JSONObject jsObjectGood32 = jsArrayGoodsList3.getJSONObject(1);
                                HotComIdStr[1] = jsObjectGood32.getString("goods_id");
                                String home3nameRightup = jsObjectGood32.getString("goods_name");
                                String home3priceRightup = jsObjectGood32.getString("goods_promotion_price");
                                String home3imgRightup = jsObjectGood32.getString("goods_image");
                                hotRightupTitleTv.setText(home3nameRightup);
                                hotRightupPriceTv.setText(home3priceRightup);
                                ImageLoader.getInstance().displayImage(home3imgRightup, hotRightupImg, FormatConfirm.getOption());

                                JSONObject jsObjectGood33 = jsArrayGoodsList3.getJSONObject(2);
                                HotComIdStr[2] = jsObjectGood33.getString("goods_id");
                                String home3nameRightdown = jsObjectGood33.getString("goods_name");
                                String home3priceRightdown = jsObjectGood33.getString("goods_promotion_price");
                                String home3imgRightdown = jsObjectGood33.getString("goods_image");

                                hotRightdownTitleTv.setText(home3nameRightdown);
                                hotRightdownPriceTv.setText(home3priceRightdown);
                                ImageLoader.getInstance().displayImage(home3imgRightdown, hotRightdownImg, FormatConfirm.getOption());
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                            return 0;
                        }
                        return 1;
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        Log.i("zhangxiaoxidebug", "getIndex....onFailure msg=" + msg);
                        Toast.makeText(getActivity(), "读取数据失败，请检查网络设置！", Toast.LENGTH_LONG).show();
                    }
                }
        );
    }

    private void getYouLike() {
        String url = "http://www.xilingou.com/mobile/index.php?act=goods&op=cainilike";
        if(MainActivity.myLogin.isLoginState())
        {
            String meminfo = "&member_id="+MainActivity.myLogin.getMemberid();
            url += meminfo;
        }
        Log.i("zhangxiaoxidebug","getYouLike url="+url);
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(2000);
        http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        int result = parseProject(responseInfo.result);
                        homeSRL.setRefreshing(false);
                        switch (result) {
                            case 1:
                                break;
                            case 0:
                                Toast.makeText(getActivity(), "读取您喜欢的商品失败，请确认网络设置后联系客服处理！", Toast.LENGTH_SHORT).show();
                                break;
                            default:
                                break;
                        }
                    }


                    @Override
                    public void onStart() {
                        homeSRL.setRefreshing(true);
                    }

                    private int parseProject(String result) {
                        Log.i("zhangxiaoxidebug", "youlike_result=" + result);
                        try {
                            JSONObject jsObjectCode = new JSONObject(result);
                            int code = jsObjectCode.getInt("code");
                            if (code != 200) {
                                return 0;
                            }
                            JSONArray jsArrayDatas = jsObjectCode.getJSONArray("data");
                            bottomGoodsTitleTv.setText("猜您喜欢");
                            goodsLists.clear();
                            for (int good = 0; good < jsArrayDatas.length(); good++)
                            {
                                JSONObject jsObjectTheGood = jsArrayDatas.getJSONObject(good);
                                String goodId = jsObjectTheGood.getString("goods_id");
                                String goods_name = jsObjectTheGood.getString("goods_name");
                                String goods_promotion_price = jsObjectTheGood.getString("goods_promotion_price");
                                String goods_image = jsObjectTheGood.getString("goods_image");
                                String goods_salenum = jsObjectTheGood.getString("goods_salenum");
                                goodsLists.add(new YouLikeGoodsBean(goodId, goods_image, goods_name, goods_promotion_price, goods_salenum));
                            }
                            recycleViewAdapter.notifyDataSetChanged();
                        } catch (JSONException e) {
                            e.printStackTrace();
                            return 0;
                        }
                        return 1;
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        homeSRL.setRefreshing(false);
                        Log.i("zhangxiaoxidebug", "getIndex....onFailure msg=" + msg);
                        Toast.makeText(getActivity(), "读取您喜欢的商品失败，请检查网络设置！", Toast.LENGTH_SHORT).show();
                    }
                }
        );
    }

    private void startIntent(String keywords)
    {
        Intent searchInt = new Intent(getActivity(),SearchResultActivity.class);
        searchInt.putExtra("SearchKeyType","keyword");
        searchInt.putExtra("SearchKeyWord",keywords);
        startActivity(searchInt);
    }
}
